generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Service {
  id Int @id @default(autoincrement())
  title String
  price Int
  priceSecond Int?
  time String @default("")
  isActive Boolean @default(true)

  categoryId Int?
  category Category? @relation(fields: [categoryId], references: [id])
}

model Category {
  id Int @id @default(autoincrement())
  title String

  services Service[]
  specialists CategoriesOnSpecialists[]
}

model Specialist {
  id Int @id @default(autoincrement())
  name String
  qualification String
  photoUrl String? @default("043343b9837fb8953545103e4071f8a3")
  timeTable String
  beginingDate String

  categories CategoriesOnSpecialists[]
  dates DatesOnSpecialists[]
}

model CategoriesOnSpecialists {
  specialist  Specialist     @relation(fields: [specialistId], references: [id], onDelete: Cascade)
  specialistId     Int
  category   Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
  categoryId Int

  @@id([specialistId, categoryId])
}

model DatesOnSpecialists {
  specialist  Specialist     @relation(fields: [specialistId], references: [id], onDelete: Cascade)
  specialistId  Int
  date Date @relation(fields: [dateId], references: [id], onDelete: Cascade)
  dateId Int

  isWorkingDate String? @default("none")
  isWorkingDateChanged Boolean @default(false)
  
  @@id([specialistId, dateId])
}

model Date {
  id Int @id @default(autoincrement())
  date String @unique
  time Time[]

  specialists DatesOnSpecialists[]
}

model Time {
  id Int @id @default(autoincrement())
  morningTime String[] @default(["9:00", "9:30", "10:00", "10:30", "11:00", "11:30"])
  afternoonTime String[] @default(["12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30"])
  eveningTime String[] @default(["18:00", "18:30", "19:00", "19:30", "20:00", "20:30"])

  dateId Int 
  date Date @relation(fields: [dateId], references: [id], onDelete: Cascade)

  specialistId Int
}

model Client {
  id Int @id @default(autoincrement())
  name String
  telegramName String @unique
  telephoneNumber String
  chatId String?
}

model Order {
  id Int @id @default(autoincrement())
  clientName String
  clientTelegram String
  clientTelephone String
  clientComment String
  clientChatId String?
  masterId Int
  masterName String
  dateTime String
  totalTime Int
  servicesInfo String
  totalPrice Int
  servicesCount Int
}

model General {
  id Int @id @default(autoincrement())
  companyTelephone String
  companyAddress String
  companyDescription String
}

model AdminInfo {
  id Int @id @default(autoincrement())
  BotPaid String @default("false") 
  payDate String
}